package com.yanqu.road.server.cmd.activity.autoreward.rank;

import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.entity.rank.stronghold.CrossActivityUnionRank;
import com.yanqu.road.logic.cross.CrossActivityRankListModel;
import com.yanqu.road.logic.cross.CrossGeneralActivityUnionRankModel;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.server.manager.activity.ActivityRankMgr;
import com.yanqu.road.server.manager.activity.CrossGeneralActivityRankMgr;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：zfr
 * @date ：2021/8/10 18:35
 */
public class DragonBoatRaceActivityRank extends BaseCrossRank {

    public DragonBoatRaceActivityRank(int activityId) {
        super(activityId);
    }

    @Override
    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg() {
        AutoSendRewardProto.CrossUserRankMsg.Builder msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
        msg.setActivityId(activityId);
        Map<Integer, CrossActivityRankListModel> modelMap = ActivityRankMgr.getCrossActivityNewRankListModelMap(activityId);
        if (modelMap != null) {
            for (Map.Entry<Integer, CrossActivityRankListModel> entry : modelMap.entrySet()) {
                CrossActivityRankListModel rankListModel = entry.getValue();
                int conditionType = rankListModel.getConditionType();
                if (conditionType != 1076) {
                    continue;
                }
                int rank = 0;
                for (CrossUserRank rankData : rankListModel.getRankList()) {
                    long userId = rankData.getUserId();
                    rank++;
                    addUserRankData(msg, conditionType, userId, rank);
                }
            }
        }
        return msg;
    }

    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg() {
        AutoSendRewardProto.CrossUnionRankMsg.Builder msg = AutoSendRewardProto.CrossUnionRankMsg.newBuilder();
        msg.setActivityId(activityId);
        HashMap<Integer, CrossGeneralActivityUnionRankModel> model = CrossGeneralActivityRankMgr.getCrossActivityUnionRankListModel(activityId);
        for (Map.Entry<Integer, CrossGeneralActivityUnionRankModel> entry : model.entrySet()) {
            CrossGeneralActivityUnionRankModel rankListModel = entry.getValue();
            int conditionType = rankListModel.getConditionType();
            if (conditionType != 1078) {
                continue;
            }
            int rank = 0;
            for (CrossActivityUnionRank rankData : rankListModel.getRankList()) {
                String unionUid = rankData.getUnionUid();
                rank++;
                addUnionRankData(msg, conditionType, unionUid, rank);
            }
        }
        return msg;
    }
}
